//
//  HotelCheckInInfoVC.swift
//  DLuxTravel
//
//  Created by 陆涛 on 2018/12/3.
//  Copyright © 2018 imguider. All rights reserved.
//

import UIKit

class HotelCheckInInfoVC: BaseVC {

    @IBOutlet weak var tableView: BaseTableView!
    
    private var hotelRoomHeadView:BookingHotelRoomHeadView?
    
    override func viewDidLoad() {
        super.viewDidLoad()

        self.navigationController?.interactivePopGestureRecognizer?.isEnabled = false;
        self.navigationController?.isNavigationBarHidden = true
        
        tableView.register(UINib(nibName: "BookingHotelInfoCell", bundle: nil), forCellReuseIdentifier: "BookingHotelInfoCell")
        
        tableView.register(UINib(nibName: "BookingHotelDateCell", bundle: nil), forCellReuseIdentifier: "BookingHotelDateCell")
        
        tableView.register(UINib(nibName: "HotelRoomCell", bundle: nil), forCellReuseIdentifier: "HotelRoomCell")
        
        tableView.register(BookingHotelRoomHeadView.self, forHeaderFooterViewReuseIdentifier: "BookingHotelRoomHeadView")
        
        tableView.sectionFooterHeight = 1
    }
    
    private func selectRoomAction() {
        
        
    }
}

extension HotelCheckInInfoVC: UITableViewDataSource, UITableViewDelegate {
    
    func numberOfSections(in tableView: UITableView) -> Int {
        
        return 2
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        
        if section == 0 {
            return 2
        }
        
        return 4
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        if indexPath.section == 0 {
            
            if indexPath.row == 0 {
                
                let cell = tableView.dequeueReusableCell(withIdentifier: "BookingHotelInfoCell") as! BookingHotelInfoCell
                
                return cell
            }
            
            let cell = tableView.dequeueReusableCell(withIdentifier: "BookingHotelDateCell") as! BookingHotelDateCell
            
            return cell
        }
        
        let cell = tableView.dequeueReusableCell(withIdentifier: "HotelRoomCell") as! HotelRoomCell
        
        return cell
        
    }
    
    func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        
        if section == 1 {
            
            if let view = hotelRoomHeadView {
                
                return view
            }
            
            let view = tableView.dequeueReusableHeaderFooterView(withIdentifier: "BookingHotelRoomHeadView") as! BookingHotelRoomHeadView
            
            view.selectRoomAction = {
                [weak self] in
                guard let `self` = self else { return }
                
                self.selectRoomAction()
            }
            
            hotelRoomHeadView = view
            
            return view
        }
        
        return nil
    }
    
    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        
        if section == 1 {
            
            return 40
        }
        
        return 0.1
    }
    
    
}
